package com.ark.cloud.javacallnative.service.impl;

import com.ark.cloud.javacallnative.entity.PlatState;
import com.ark.cloud.javacallnative.entity.SensorData;
import com.ark.cloud.javacallnative.entity.ServerInfo;
import com.ark.cloud.javacallnative.entity.WaypointCmd;
import com.ark.cloud.javacallnative.jni.JNICallNative;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import java.util.ArrayList;

/**
 * Copyright(c): 2021 Cloud-Ark Inc.
 * Author(s): Ma Wei (mawei@cloud-ark.com)
 */
@Service
public class ProducerServiceImpl {

    @Value("${kafka.host:}")
    private String[] kafkaHost;


    @PostConstruct

    public void run() {
        //测试模拟生产者
        JNICallNative.DataBus_Init();
        ArrayList<ServerInfo> servers = new ArrayList();
        for (String host : kafkaHost) {
            String[] split = host.split(":");
            ServerInfo server = new ServerInfo();
            server.setsServerIp(split[0]);
            server.setnServerPort(Integer.parseInt(split[1]));
            servers.add(server);
        }
        JNICallNative.DataBus_Register_Servers(servers);
        ArrayList<String> subStrings = new ArrayList();
        subStrings.add("PlatState");
        subStrings.add("SensorData");
        subStrings.add("ScenarioState");
        subStrings.add("ContactState");

        subStrings.add("FireEvent");
        subStrings.add("ExplodeEvent");
        subStrings.add("DetectEvent");
        subStrings.add("BGCMD");
        subStrings.add("SensorOnOffEvent");
        subStrings.add("CommunicationEvent");
        subStrings.add("DestoryEvent");
        subStrings.add("SimEngineState");
        subStrings.add("AircraftStatus");

        subStrings.add("ReplyCmd");
        subStrings.add("AircraftLaunchCmd");
        subStrings.add("SpeedCmd");
        subStrings.add("WaypointCmd");
        subStrings.add("JammerCmd");
        subStrings.add("GuideCmd");
        JNICallNative.DataBus_Register_Publish_List(subStrings);
        JNICallNative.DataBus_Start();

        try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        JNICallNative.DataBus_SendMsg_SensorObj(new SensorData());
        JNICallNative.DataBus_SendMsg_WaypointCmd(new WaypointCmd());
        JNICallNative.DataBus_SendMsg_PlatState(new PlatState());



    }



}
